package com.aistar.config;

import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class EC_QuartzConfig {

    private  static  final String LIKE_TASK_IDENTITY = "LikeTaskQuartz";

    private static final String SE_TASK_IDENTITY = "EsTaskQuartz";

    @Bean
    public JobDetail quartzDetail(){
        return JobBuilder.newJob(C_LikeTask.class).withIdentity(LIKE_TASK_IDENTITY).storeDurably().build();
    }

    @Bean
    public Trigger quartzTrigger() {
        SimpleScheduleBuilder scheduleBuilder = SimpleScheduleBuilder.simpleSchedule()
                .withIntervalInSeconds(5)  //设置时间周期单位秒
 //               .withIntervalInHours(2)  //两个小时执行一次
                .repeatForever();
        return TriggerBuilder.newTrigger().forJob(quartzDetail())
                .withIdentity(LIKE_TASK_IDENTITY)
                .withSchedule(scheduleBuilder)//CronScheduleBuilder.cronSchedule("0 40 17 ? * *")
                .build();
    }

    @Bean
    public JobDetail quartzES(){
        return JobBuilder.newJob(ESTask.class).withIdentity(SE_TASK_IDENTITY).storeDurably().build();
    }

    @Bean
    public Trigger quartzTrigger_ES() {
        SimpleScheduleBuilder scheduleBuilder = SimpleScheduleBuilder.simpleSchedule()
                .withIntervalInSeconds(20)  //设置时间周期单位秒
                //               .withIntervalInHours(2)  //两个小时执行一次
                .repeatForever();
        return TriggerBuilder.newTrigger().forJob(quartzES())
                .withIdentity(SE_TASK_IDENTITY)
                .withSchedule(scheduleBuilder)//CronScheduleBuilder.cronSchedule("0 40 17 ? * *")
                .build();
    }

}
